package com.biblum.topgas;

import android.app.ListActivity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ListView;
import android.widget.TextView;

import com.biblum.topgas.R;
import com.google.ads.AdView;


public class TopGasListActivity extends ListActivity {
		
	EstacionesData topgasData;
	TopGasAdapter adapter;
	boolean byDistance = false;
	
	public void onCreate(Bundle icicle) {
        super.onCreate(icicle);

		// No Titlebar
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		requestWindowFeature(Window.FEATURE_PROGRESS);
 	    
	    setContentView(R.layout.topgas_list);
        
	    // Look up the AdView as a resource and load a request.
		MyAdManager.initialize(this);
	    MyAdManager.loadAd((AdView)this.findViewById(R.id.adView));
	    
	    Bundle bundle = getIntent().getExtras();	    
	    String elTitulo = bundle.getString(Constantes.ATRIBUTO_TITULO);
		TextView title = (TextView) this.findViewById(R.id.Title);
		title.setText(elTitulo);
		
        adapter = new TopGasAdapter(getApplicationContext());
		setListAdapter(adapter);
		
        topgasData = EstacionesData.getInstance(this);
    }
	
	@Override
	protected void onResume() {
		super.onResume();
		
		SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);		
		Boolean fullscreen = sharedPrefs.getBoolean("fullscreen", false);
		adapter.notifyDataSetChanged();
		
		// No Statusbar
		if (fullscreen) {
			getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
		} else {
			getWindow().setFlags(0, WindowManager.LayoutParams.FLAG_FULLSCREEN);
		}
	}

	@Override
	protected void onPause() {
		super.onPause();

	}

	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		super.onListItemClick(l, v, position, id);

		Intent intent = new Intent(this, TopGasDetalleActivity.class);
		Bundle bundle = new Bundle();
		bundle.putInt("selectedPlace", position);
		bundle.putBoolean("calledFromMap", false);
		intent.putExtras(bundle);
		startActivity(intent);
	}
	
	public void onBackAction(View v) {
		finish();
	}
	
	public void onPreferencesAction(View v) {
		Intent intent = new Intent(this, PreferencesActivity.class);
		startActivity(intent);
	}
}